package com.liberation.aidiancan.base.rebaseadapter;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.liberation.aidiancan.R;
import com.liberation.aidiancan.widget.GlideRoundTransform;


import java.util.List;

import me.next.tagview.TagCloudView;

/**
 * Created by Administrator on 2016/10/31.
 */


public class MyHolder extends RecyclerView.ViewHolder {
    public int HOlder_TYPE ;
    SparseArray<View> views = new SparseArray<>();
    View myConvertView;

    public MyHolder(View itemView) {
        super(itemView);
        myConvertView = itemView;
        this.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

    //返回当前id的view，如果不能在list中找到，则到布局找
    public View getView(int id) {
        View view = views.get(id);
        if (view == null) {
            Log.e("msg", "getView: 需要子控件");
            view = myConvertView.findViewById(id);
            views.put(id, view);
        }
        return view;
    }

    //给v指定id的view添加字符串
    public void setText(int id, String text) {
        if (text != null) {
            ((TextView) getView(id)).setText(text+"");
        }

    }

    public void setTagContent(int id,List<String> stringList){
        if(stringList.size()>0){
            ((TagCloudView) (getView(id))).setTags(stringList);
        }
    }

    public void setImage(int id, String url) {
        if (url != null) {
            ImageView imageView = (ImageView) getView(id);
            Glide.with(imageView.getContext())
                    .load(url)
                   // .thumbnail(0.1f)//加载略缩图
                    .diskCacheStrategy(DiskCacheStrategy.NONE )//不缓存所有图片
                    .error(R.mipmap.ic_launcher)//下载错误时的替换
                    .dontAnimate() //不加载动画效果
                    .fitCenter()  //默认全屏居中
                    .into(imageView);

        }
    }

    public void setRoundImag(int id,String url){
        if (url != null) {
            ImageView imageView = (ImageView) getView(id);
            RequestManager glideRequest= Glide.with(imageView.getContext());
            glideRequest.load(url).
                    error(R.mipmap.ic_launcher)//下载错误时的替换
                    .dontAnimate() //不加载动画效果
                    .fitCenter()  //默认全屏居中
                    .transform(new GlideRoundTransform(imageView.getContext(), 5)).into(imageView);
        }
    }
}